﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using VoL.Domain.Infrastructure;
using VoL.Domain.IServices.DoctorManage;
using VoL.Domain.Repositories;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers
{
    /// <summary>
    /// 医生管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DoctorManageController : ControllerBase
    {
        private readonly IDoctorManageServices _doctorManageServices;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="doctorManageServices"></param>
        public DoctorManageController(IDoctorManageServices doctorManageServices)
        {
            this._doctorManageServices = doctorManageServices;
        }

        /// <summary>
        /// 查询入量
        /// </summary>
        /// <param name="patientCode">患者编号</param>
        /// <param name="firstTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>返回</returns>
        [HttpGet]
        public Task<WebResponseContent> GetInRecords(string patientCode, DateTime? firstTime, DateTime ?endTime)
        {
            return _doctorManageServices.GetInRecords(patientCode,firstTime,endTime);
        }

        /// <summary>
        /// 查询出量
        /// </summary>
        /// <param name="patientCode">患者编号</param>
        /// <param name="firstTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>返回</returns>
        [HttpGet]
        public Task<WebResponseContent> GetOutRecords(string patientCode, DateTime? firstTime, DateTime? endTime)
        {
        
            return _doctorManageServices.GetOutRecords(patientCode, firstTime, endTime);
           
        }

        /// <summary>
        /// 获取患者列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<WebResponseContent> GetPatients()
        {
            return _doctorManageServices.GetPatients();
        }

        /// <summary>
        /// 查询日常护理
        /// </summary>
        /// <param name="patientCode">患者编号</param>
        /// <returns>返回</returns>
        [HttpGet]
        public Task<WebResponseContent> GetPatientReCords(string patientCode)
        {
            return _doctorManageServices.GetPatientReCords(patientCode);
        }

        /// <summary>
        /// 根据患者编号查询患者信息成功
        /// </summary>
        /// <param name="patientCode">患者编号</param>
        /// <returns>返回</returns>
        [HttpGet]
        public Task<WebResponseContent> GetPatientsByPatientCode(string patientCode)
        {
            return _doctorManageServices.GetPatientsByPatientCode(patientCode);
        }
        /// <summary>
        /// 创建医嘱
        /// </summary>
        /// <param name="tell">医嘱信息</param>
        /// <returns>返回创建结果</returns>
        [HttpPost]
        public async Task<WebResponseContent> CreateTell([FromBody]Tell tell)
        {
            return await _doctorManageServices.CreateTell(tell);
        }
        /// <summary>
        /// 删除医嘱（软删除）
        /// </summary>
        /// <param name="id">医嘱ID</param>
        /// <returns>返回删除结果</returns>
        [HttpPost]
        public async Task<WebResponseContent> DeleteTell([FromQuery]int id)
        {
            return await _doctorManageServices.DeleteTell(id);
        }

        /// <summary>
        /// 更新医嘱
        /// </summary>
        /// <param name="tell">医嘱信息</param>
        /// <returns>返回更新结果</returns>
        [HttpPost]
        public async Task<WebResponseContent> UpdateTell([FromBody] Tell tell)
        {
            return await _doctorManageServices.UpdateTell(tell);
        }

        /// <summary>
        /// 获取医嘱列表（支持模糊查询）
        /// </summary>
        /// <param name="patientCode">患者编号（支持模糊查询）</param>
        /// <returns>返回医嘱列表</returns>
        [HttpGet]
        public async Task<WebResponseContent> GetTells(string? patientCode)
        {
            return await _doctorManageServices.GetTells(patientCode);
        }

        /// <summary>
        /// 修改发布状态
        /// </summary>
        /// <param name="id">主键Id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> Updatesatus(int id)
        {
            return await _doctorManageServices.Updatesatus(id);
        }

        /// <summary>
        /// 获取发布成功后的信息
        /// </summary> 
        /// <returns>返回医嘱列表</returns>
        [HttpGet]
        public async Task<WebResponseContent> GetTellsPublisher(string? patientCode)
        {
            return await _doctorManageServices.GetTellsPublisher(patientCode);
        }


        /// <summary>
        /// 修改发布状态
        /// </summary>
        /// <param name="id">主键Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebResponseContent> GetBed()
        {
            return await _doctorManageServices.GetBed();
        }

    }
}
